package com.ubs.training.server.service;

import com.ubs.training.prod.server.service.LoggingService;
import com.ubs.training.server.dao.TypeDao;
import com.ubs.training.server.dao.model.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/22/12
 * Time: 2:30 PM
 * To change this template use File | Settings | File Templates.
 */
@Service
public class TypeService {
    @Resource(name = "typeDao")
    TypeDao dao;

    @Autowired
    LoggingService svc;
    public static final String USER_REQUESTS_ALL_TYPES ="user requested all types" ;
    public static final String USER_UPDATED_TYPE ="user updated type" ;
    public static final String USER_ADDED_TYPE ="user added type";
    public static final String USER_REMOVED_TYPE ="user removed type" ;
    public static final String USER_REQUESTED_TYPE_BY_ID ="user requested type by id" ;

    public TypeDao getDao() {
        return dao;
    }

    public void setDao(TypeDao dao) {
        this.dao = dao;
    }

    public LoggingService getSvc() {
        return svc;
    }

    public void setSvc(LoggingService svc) {
        this.svc = svc;
    }
    public List<Type> getAll(){

        return dao.getAll();
    }
    public void saveType(Type type){
        if (dao.getAll().contains(type)){
            dao.update(type);

        }
        else {
            dao.add(type);

        }
    }
    public void delete(Type type){
        dao.remove(type);

    }
    public Type getById(int id){

        return dao.getById(id);
    }
}
